package com.iweb.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iweb.mapper.UserMapper;
import com.iweb.model.Game;
import com.iweb.model.OrderG;
import com.iweb.model.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Time :2022/8/15 13:15
 * Author : kriller
 * Project : steam-malls
 */
@Service
public class UserService {
    @Resource
    private UserMapper userMapper;

    public void insertUser(User user) {
        userMapper.insertUser(user);
    }

    public User findUserById(Integer userId) {
        User user = userMapper.selectById(userId);
        return user;
    }

    public User findByAccount(String userAccount) {
        User user = userMapper.selectByAccount(userAccount);
        return user;
    }

    public List<Game> getWishList(Integer userId) {
        List<Game> games = userMapper.getWishList(userId);
        return games;
    }

    public List<User> listUserBypage() {
        //PageHelper.startPage(page,10);

        List<User> users = userMapper.selectUser();

        //PageInfo<User> info = new PageInfo<>(users);
        //return info.getList();
        return users;
    }

    public void updateUserState(User user) {
        userMapper.updateUserState(user);
    }

    public List<OrderG> getUserGame(Integer userId) {
        List<OrderG> games = userMapper.selectUserGame(userId);
        return games;
    }

    public void updateUser(User user) {
        userMapper.updateUserById(user);
    }

    public void deleteByUserIdAndGameId(Integer userId, Integer gameId) {
        Map<String,Integer> map = new HashMap<>();
        map.put("userId",userId);
        map.put("gameId",gameId);
        userMapper.deleteWish(map);
    }

    public void insertWish(Integer userId, Integer gameId) {
        Map<String,Integer> map = new HashMap<>();
        map.put("userId",userId);
        map.put("gameId",gameId);
        userMapper.insertWish(map);

    }

    public Integer findWishByUGId(Integer userId,Integer gameId) {
        Map<String,Integer> map = new HashMap<>();
        map.put("userId",userId);
        map.put("gameId",gameId);
        Integer wishId = userMapper.selectWishId(map);
        return wishId;
    }
}
